package com.rock.code.common.comm;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DateUtil2
{
  private static Log log = LogFactory.getLog(DateUtil.class);
  private static String defaultDatePattern = "yyyy-MM-dd";
  public static String inputDatePattern = "yyyyMMdd";
  public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
  private static String timePattern = "HH:mm";
  private static final SimpleDateFormat mFormat8chars = new SimpleDateFormat("yyyyMMdd");
  private static final SimpleDateFormat mFormatIso8601Day = new SimpleDateFormat("yyyy-MM-dd");
  private static final SimpleDateFormat mFormatZh = new SimpleDateFormat("yyyy年MM月dd日");
  private static final SimpleDateFormat mFormatIso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
  private static final SimpleDateFormat mFormatRfc822 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
  private static final SimpleDateFormat mFormatForPrinting = new SimpleDateFormat("dd MMM,yyyy", Locale.ENGLISH);

  public static String getDatePattern()
  {
    return defaultDatePattern;
  }

  public static final String getDate(java.util.Date paramDate)
  {
    SimpleDateFormat localSimpleDateFormat = null;
    String str = "";
    if (paramDate != null)
    {
      localSimpleDateFormat = new SimpleDateFormat(getDatePattern());
      str = localSimpleDateFormat.format(paramDate);
    }
    return str;
  }

  public static final java.util.Date convertStringToDate(String paramString1, String paramString2)
    throws ParseException
  {
    SimpleDateFormat localSimpleDateFormat = null;
    java.util.Date localDate = null;
    localSimpleDateFormat = new SimpleDateFormat(paramString1);
    if (log.isDebugEnabled())
      log.debug("converting '" + paramString2 + "' to date with mask '" + paramString1 + "'");
    try
    {
      localDate = localSimpleDateFormat.parse(paramString2);
    }
    catch (ParseException localParseException)
    {
      throw new ParseException(localParseException.getMessage(), localParseException.getErrorOffset());
    }
    return localDate;
  }

  public static final java.sql.Date convertUtilDateToSqlDate(java.util.Date paramDate)
  {
    java.sql.Date localDate = new java.sql.Date(paramDate.getTime());
    return localDate;
  }

  public static String getTimeNow(java.util.Date paramDate)
  {
    return getDateTime(timePattern, paramDate);
  }

  public static Calendar getToday()
    throws ParseException
  {
    java.util.Date localDate = new java.util.Date();
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(getDatePattern());
    String str = localSimpleDateFormat.format(localDate);
    GregorianCalendar localGregorianCalendar = new GregorianCalendar();
    localGregorianCalendar.setTime(convertStringToDate(str));
    return localGregorianCalendar;
  }

  public static final String getDateTime(String paramString, java.util.Date paramDate)
  {
    SimpleDateFormat localSimpleDateFormat = null;
    String str = "";
    if (paramDate == null)
    {
      log.error("aDate is null!");
    }
    else
    {
      localSimpleDateFormat = new SimpleDateFormat(paramString);
      str = localSimpleDateFormat.format(paramDate);
    }
    return str;
  }

  public static final String convertDateToString(java.util.Date paramDate)
  {
    return getDateTime(getDatePattern(), paramDate);
  }

  public static final String convertDateToString(String paramString, java.util.Date paramDate)
  {
    return getDateTime(paramString, paramDate);
  }

  public static java.util.Date convertStringToDate(String paramString)
    throws ParseException
  {
    java.util.Date localDate = null;
    try
    {
      if (log.isDebugEnabled())
        log.debug("converting date with pattern: " + getDatePattern());
      localDate = convertStringToDate(getDatePattern(), paramString);
    }
    catch (ParseException localParseException)
    {
      log.error("Could not convert '" + paramString + "' to a date, throwing exception");
      localParseException.printStackTrace();
      throw new ParseException(localParseException.getMessage(), localParseException.getErrorOffset());
    }
    return localDate;
  }

  public static String format(java.util.Date paramDate, SimpleDateFormat paramSimpleDateFormat)
  {
    if ((paramDate == null) || (paramSimpleDateFormat == null))
      return "";
    return paramSimpleDateFormat.format(paramDate);
  }

  public static String format(java.util.Date paramDate, String paramString)
  {
    if ((paramDate == null) || (paramString == null))
      return "";
    return new SimpleDateFormat(paramString).format(paramDate);
  }

  public static String getDefaultDateFormat(java.util.Date paramDate)
  {
    return DateUtil.format(paramDate, mFormatIso8601Day);
  }

  public static String getTimeFormat(java.util.Date paramDate)
  {
    return DateUtil.format(paramDate, mFormatIso8601);
  }

  public static String getPrintedDateFormat(java.util.Date paramDate)
  {
    return DateUtil.format(paramDate, mFormatForPrinting);
  }

  public static String getZhTimeFormat(java.util.Date paramDate)
  {
    return DateUtil.format(paramDate, mFormatZh);
  }

  public static String getDefaultDateFormat(long paramLong)
  {
    java.util.Date localDate = new java.util.Date();
    localDate.setTime(paramLong);
    return DateUtil.format(localDate, mFormatIso8601Day);
  }

  public static String getDateofneed(int paramInt)
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    java.util.Date localDate = new java.util.Date();
    long l = localDate.getTime() / 1000L + 86400 * paramInt;
    localDate.setTime(l * 1000L);
    String str = localSimpleDateFormat.format(localDate);
    return str;
  }

  public static String getYear(java.util.Date paramDate)
  {
    String str1 = DateUtil.getDefaultDateFormat(paramDate.getTime());
    String str2 = str1.substring(0, 4);
    return str2;
  }

  public static String getMonth(java.util.Date paramDate)
  {
    String str1 = DateUtil.getDefaultDateFormat(paramDate.getTime());
    String str2 = str1.substring(5, 7);
    return str2;
  }

  public static String getMonth2(java.util.Date paramDate)
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("MM");
    return localSimpleDateFormat.format(paramDate);
  }

  public static String getDay(java.util.Date paramDate)
  {
    String str1 = DateUtil.getDefaultDateFormat(paramDate.getTime());
    String str2 = str1.substring(8, 10);
    return str2;
  }

  public static String getDirectoryByDate(java.util.Date paramDate)
  {
    return getYear(paramDate) + File.separator + getMonth(paramDate) + File.separator;
  }

  public static String getUrlByDate(java.util.Date paramDate)
  {
    return getYear(paramDate) + "/" + getMonth(paramDate) + "/";
  }

  public static synchronized java.util.Date addDays(java.util.Date paramDate, int paramInt)
  {
    return Add(paramDate, paramInt, 0, 0, 0);
  }

  public static synchronized java.util.Date Add(java.util.Date paramDate, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    java.util.Date localDate = paramDate;
    if (localDate != null)
    {
      Calendar localCalendar = Calendar.getInstance();
      localCalendar.setTime(localDate);
      if (paramInt1 != 0)
        localCalendar.add(5, paramInt1);
      if (paramInt2 != 0)
        localCalendar.add(10, paramInt2);
      if (paramInt3 != 0)
        localCalendar.add(12, paramInt3);
      if (paramInt4 != 0)
        localCalendar.add(13, paramInt4);
      localDate = localCalendar.getTime();
    }
    return localDate;
  }

  public static int getCurrentYear()
  {
    Calendar localCalendar = Calendar.getInstance();
    return localCalendar.get(1);
  }

  public static java.util.Date getNextTuesDayOrFriday(java.util.Date paramDate)
  {
    if (paramDate != null)
      do
        paramDate = Add(paramDate, 1, 0, 0, 0);
      while ((paramDate.getDay() != 2) && (paramDate.getDay() != 5));
    return paramDate;
  }

  public static String getTimePattern()
  {
    return timePattern;
  }

  public String getStringTime(java.util.Date paramDate)
  {
    if (paramDate == null)
      return "";
    String str = DateUtil.getDateTime("yyyyMMdd HH:mm:ss", paramDate);
    return str;
  }

  public static boolean isValid(String paramString)
  {
    return isValid(paramString, defaultDatePattern);
  }

  public static boolean isValid(String paramString1, String paramString2)
  {
    //if (StringUtils.isEmpty(paramString1))
    if (paramString1==null||"".equals(paramString1))
      return false;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString2);
    java.util.Date localDate = null;
    try
    {
      localDate = localSimpleDateFormat.parse(paramString1);
    }
    catch (ParseException localParseException)
    {
      return false;
    }
    return (localSimpleDateFormat.format(localDate).equals(paramString1));
  }

  public static long diffDate(java.util.Date paramDate1, java.util.Date paramDate2)
  {
    long l1 = 0L;
    try
    {
      java.util.Date localDate1 = DateUtil.convertStringToDate("yyyyMMdd", DateUtil.format(paramDate1, "yyyyMMdd"));
      java.util.Date localDate2 = DateUtil.convertStringToDate("yyyyMMdd", DateUtil.format(paramDate2, "yyyyMMdd"));
      long l2 = localDate1.getTime();
      long l3 = localDate2.getTime();
      l1 = (l2 - l3) / 86400000L;
    }
    catch (ParseException localParseException)
    {
      localParseException.printStackTrace();
      l1 = 0L;
    }
    return l1;
  }

  public static boolean isStrictDate(String paramString)
  {
    String str = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
    Pattern localPattern = Pattern.compile(str);
    Matcher localMatcher = localPattern.matcher(paramString);
    return localMatcher.matches();
  }

  public static boolean before(java.util.Date paramDate1, java.util.Date paramDate2)
    throws Exception
  {
    if ((null != paramDate1) && (null == paramDate2))
      return true;
    if ((null != paramDate1) && (null != paramDate2))
    {
      long l1 = paramDate1.getTime();
      long l2 = paramDate2.getTime();
      if (l1 < l2)
        return true;
    }
    return false;
  }

  public static boolean equalsDate(java.util.Date paramDate1, java.util.Date paramDate2)
  {
    if ((null == paramDate1) && (null == paramDate2))
      return true;
    if ((null != paramDate1) && (null != paramDate2))
    {
      long l1 = paramDate1.getTime();
      long l2 = paramDate2.getTime();
      if (l1 == l2)
        return true;
    }
    return false;
  }

  public static boolean after(java.util.Date paramDate1, java.util.Date paramDate2)
  {
    if ((null == paramDate1) && (null != paramDate2))
      return true;
    if ((null != paramDate1) && (null != paramDate2))
    {
      long l1 = paramDate1.getTime();
      long l2 = paramDate2.getTime();
      if (l1 > l2)
        return true;
    }
    return false;
  }

  public static final java.util.Date stringDateToDate(String paramString1, String paramString2)
    throws ParseException
  {
    java.util.Date localDate = null;
    if ((null == paramString1) || ("".equals(paramString1)))
      return localDate;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString2);
    if (log.isDebugEnabled())
      log.debug("converting '" + paramString1 + "' to date with mask '" + paramString2 + "'");
    try
    {
      localDate = localSimpleDateFormat.parse(paramString1);
    }
    catch (ParseException localParseException)
    {
      throw new ParseException(localParseException.getMessage(), localParseException.getErrorOffset());
    }
    return localDate;
  }

  public static final boolean betWeenDate(java.util.Date paramDate1, java.util.Date paramDate2, java.util.Date paramDate3)
    throws Exception
  {
    if ((null == paramDate2) && (null == paramDate3))
      return true;
    return ((null != paramDate2) && (((before(paramDate1, paramDate3)) || (equalsDate(paramDate1, paramDate3)))) && (((after(paramDate1, paramDate2)) || (equalsDate(paramDate1, paramDate2)))));
  }
}

/* Location:           C:\Users\think\Desktop\新建文件夹 (2)\bomc-web.jar
 * Qualified Name:     com.sitech.ibnms.util.DateUtil2
 * JD-Core Version:    0.5.3
 */